package com.github.shiqiyue.app.api.sapi.controller.dbms.dto;

import com.github.shiqiyue.app.common.result.BasePageResult;
import com.github.shiqiyue.app.modules.dbms.entity.DatabaseHistory;
import lombok.Data;

import java.util.Date;
import java.util.List;

/***
 * 数据库-历史记录-分页返回结果
 * @author wenyao.wu
 * @date 2019/8/7
 */
@Data
public class DatabaseHistoryPageDTO extends BasePageResult {


    private List<Item> records;

    @Data
    public static class Item {

        private String type;

        private Date addDate;

        private String username;

        private String remark;


        public static Item newInstance(DatabaseHistory databaseHistory) {
            Item item = new Item();
            item.setType(databaseHistory.getType().getName());
            item.setAddDate(databaseHistory.getAddDate());
            item.setRemark(databaseHistory.getRemark());
            if (databaseHistory.getUser() != null) {
                item.setUsername(databaseHistory.getUser().getName());
            }
            return item;
        }

    }

}
